Ext.define('CDR.view.manager.provider.ServiceProvider', {
	extend: 'Ext.Panel',
	alias : 'widget.serviceprovider',
	title: 'Service Provider',
	selectedProviderId : 0,
	trunk : null,
	profileCenter : null,
	initComponent: function() {
		var me = this;
		me.callParent();
		
	},
	layout:'anchor',
	dockedItems: [{
		xtype: 'toolbar',
		items: [{
			text: CDR.I18N['profile.new.provider'],
			iconCls: 'icon-add',
			handler: function(){
				var me = this.up('panel');
				me.win.show();
			}
		},'-', {
			text: 'Edit Provider',
			iconCls: 'icon-edit',
			handler: function(){
				var me = this.up('panel');
				me.win.show();
			}
		}]
	}], 
	addItem: function(name, id){
		var me = this;
		this.add({
			obId: id,
			anchor:'100%',
			xtype : 'button',
            text    : name,
			scale: 'large',
			margin: '0 0 10px 0',
			enableToggle: true,
			toggleGroup:'serviceprovider_bnt',
			handler: function(){
				me.selectedProviderId = this.obId;
				//get list
				if (me.trunk) {
					var store = me.trunk.view.store;
					store.setProxy({
					  type: 'ajax',
					  url : 'list-trunk-view?serviceProviderId=' + me.selectedProviderId,
					  reader: {
						  type: 'json',
						  root: 'results'
					  }
					});
					store.load();
				}
			}
		});
	},
	submitOk: function(data) {
		this.addItem(data.name, data.id);
	},
	listeners: {
		expand : function(){
			this.profileCenter.removeAll(false);
			this.profileCenter.add(this.trunk);
		}
	}
});